<?php  # Script -- brodcast.php

/* Author @ Huoty
 *   Date @ 2015-11-17 09:58:25
 *  Brief @ 
 */

$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
//使用IPV4格式地址，数据报形式，UDP方式传输数据

socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);//设置为广播方式

$msg = 'hello world'; //要发送的字符串

while ( true ) {
	socket_sendto($sock, $msg, strlen($msg), 0, "192.168.12.255", 12345);
	//发送，255.255.255.255是广播地址，60000是端口
	echo "broadcast...\n";
	sleep( 2 );
}

socket_close($sock);//关闭
?>
